/**
 * Description: TradingType.java
 * All Rights Reserved.
 * @version 3.2  2013-10-17 下午4:30:38  by 李青原（liqingyuan1986@aliyun.com）创建
 */
package controller.cartp;

import com.zuche.framework.tradingPlatform.OperType;
import org.apache.commons.lang.ArrayUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 交易服务,交易类型类:用来指定交易请求的交易类型.
 * <br/> Created on 2013-10-17 下午4:30:38
 * @author  李青原(liqingyuan1986@aliyun.com)
 * @since 3.2.2
 * @see RequestParams#GROUP_TYPE
 */
public final class GroupType {
    /**
     * 网银支付模式
     * @since 3.2.2
     */
    public static final String WEB_BANK = "webBank";

    /**
     * 无卡支付支付模式
     * @since 3.2.3
     */
    public static final String EPOS_PAY = "eposPay";

    /**
     * 无卡支付订单取消模式
     * @since 3.2.5
     */
    public static final String EPOS_PAY_CANCEL = "eposPayCancel";

    /**
     * 无卡支付退款模式
     * @since 3.2.5
     */
    public static final String EPOS_PAY_REFUND = "eposPayRefund";

    /**
     * 无卡支付 预授权冻结
     * @since 3.2.10
     */
    public static final String EPOS_AUTH_FREEZE = "eposAuthFreeze";

    /**
     * 无卡支付 预授权撤销
     * @since 3.2.10
     */
    public static final String EPOS_AUTH_CANCEL = "eposAuthCancel";

    /**
     * 无卡支付 预授权完成撤销
     * @since 3.2.14
     */
    public static final String EPOS_AUTH_CONF_CANCEL = "eposAuthConfCancel";

    /**
     * 预授权完成模式
     * @since 3.2.12
     */
    public static final String EPOS_AUTH_CONFIRM = "eposAuthConfirm";

    /**
     * 网银支持列表查询
     * @since 3.2.6
     */
    public static final String QUERY_WEB_BANK = "webBankQuery";

    /**
     * 无卡支付支持列表查询
     * @since 3.2.6
     */
    public static final String QUERY_EPOS_BANK = "eposBankQuery";

    /**
     * 订单操作查询模式
     * @since 3.2.6
     */
    public static final String QUERY_OPER = "operQuery";

    /**
     * 订单查询模式
     * @since 3.2.7
     */
    public static final String QUERY_ORDER = "eposOrderQuery";

    /**
     * 微信二维码支付模式
     */
    public static final String WECHAT_IMG = "wechatImg";

    /**
     * 微信手机APP支付模式
     */
    public static final String WECHAT_MOBILE = "wechatMobile";

    /**
     * 卡信息查询模式
     * @since 3.2.8
     */
    public static final String QUERY_CARD_INFO = "queryCardInfo";

    public static final String CREATE_NO = "createNo";

    public static final String ALI_DIRECT = "aliDirect";

    public static final String COMPLETE_INFO = "completeInfo";
    /**
     * 发送验证码
     */
    public static final String CREATE_NO_SMS = "createNoSms";
    /**
     * 解绑信用卡
     */
    public static final String UNBIND_CREDIT_CARD = "unbindCreditCard";

    /**
     * EPOS新消费
     */
    public static final String EPOS_PAY_SMS = "eposPaySms";

    /**
     * EPOS新预授权
     */
    public static final String EPOS_AUTH_SMS = "eposAuthSms";
    /**
     * 绑定信用卡并消费
     */
    public static final String QUERY_CREDITCARD_BIND = "queryCreditcardBind";

    /**
     * 微信统一支付
     */
    public static final String WECHAT_UNIFY = "wechatUnify";

    /**
     * 支持列表统一查询
     */
    public static final String QUERY_SUPPORT = "querySupport";

    public static final String ALI_SDK = "aliSDK";

    /**
     * 线下POS预授权
     */
    public static final String POS_AUTH_FREEZE = "posAuthFreeze";
    /**
     * 线下POS预授权完成
     */
    public static final String POS_AUTH_CONFIRM = "posAuthConfirm";
    /**
     * 线下POS预授权撤销
     */
    public static final String POS_AUTH_CANCEL = "posAuthCancel";
    /**
     * 线下POS预授权撤销完成
     */
    public static final String POS_AUTH_CONF_CANCEL = "posAuthConfCancel";
    /**
     * 线下POS消费
     */
    public static final String POS_PAY = "posPay";
    /**
     * 线下POS消费撤销
     */
    public static final String POS_PAY_CANCEL = "posPayCancel";
    /**
     * 线下POS消费退款
     */
    public static final String POS_PAY_REFUND = "posPayRefund";

    /**
     * 电子小票下载
     */
    public static final String BILL_DOWNLOAD = "billDownload";
    /**
     * PAYPAL账户绑定
     */
    public static final String PAYPAL_BIND = "paypalBind";
    /**
     * PAYPAL账户支付
     */
    public static final String PAYPAL_PAY = "paypalPay";
    /**
     * PAYPAL账户解绑
     */
    public static final String PAYPAL_UNBIND = "paypalUnbind";
    /**
     * 提现转账
     */
    public static final String DRAWING = "drawing";

    public static final String QUERY_DRAWING = "queryDrawing";

    /**
     * PCI 查询
     */
    public static final String PCI_QUERY = "PCIQuery";

    /**
     * 快捷通 二次支付发短信
     */
    public static final String EPOS_QUICK_PAY_SMS = "eposQuickPaySms";

    /**
     * 快捷通-二次支付
     */
    public static final String EPOS_REQUICK_PAY = "eposReQuickPay";

    /**
     * applepay支付
     * @since 4.1.38
     */
    public static final String APPLE_PAY = "applePay";

    /**
     * 易联H5支付
     */
    public static final String EASY_LINK_WEBPAY = "easyLinkWebPay";

    /**
     * 易联短信H5支付
     */
    public static final String EASY_LINK_SMS_H5 = "easyLinkSmsH5";

    /**
     * 易联sdk密码键盘
     */
    public static final String EASY_LINK_SDK_PASS = "easyLinkSdkPass";

    //***************银联groupType**************//
    /**
     * 预授权申请
     */
    public static final String UNION_AUTH = "unionAuth";

    /**
     *预授权完成
     */
    public static final String UNION_AUTH_CONFIRM = "unionAuthConfirm";

    /**
     *预授权申请撤销
     */
    public static final String UNION_AUTH_CANCEL = "unionAuthCancel";

    /**
     *预授权完成撤销
     */
    public static final String UNION_AUTH_CONFIRM_CANCEL = "unionAuthConfirmCancel";

    /**
     *发送验证短信
     */
    public static final String UNION_SEND_SMS = "unionSendSms";

    /**
     *短信消费
     */
    public static final String UNION_SMS_PAY = "unionSmsPay";

    /**
     *直接消费
     */
    public static final String UNION_QUICK_PAY = "unionQuickPay";

    /**
     *APP消费
     */
    public static final String UNION_APP_PAY = "unionAppPay";

    /**
     *web消费
     */
    public static final String UNION_WEB_PAY = "unionWebPay";

    /**
     *消费退款
     */
    public static final String UNION_REFUND = "unionRefund";

    /**
     *消费撤销
     */
    public static final String UNION_CANCEL = "unionPayCancel";

    //***************银联groupType**************//


    /**
     * 开放平台第三方支付(targetGroup,开放平台创建交易流水使用)
     */
    public static final String OPEN_API = "openApi";

    private static Map<String,String> nameMap = new HashMap<String,String>();

    static{
        nameMap.put(GroupType.EPOS_PAY, "快捷通-消费");
        nameMap.put(GroupType.EPOS_PAY_CANCEL, "快捷通-消费撤销");
        nameMap.put(GroupType.EPOS_PAY_REFUND, "快捷通-消费退款");
        nameMap.put(GroupType.EPOS_AUTH_CANCEL, "快捷通-预授权撤销");
        nameMap.put(GroupType.EPOS_AUTH_CONF_CANCEL, "快捷通-预授权完成撤销");
        nameMap.put(GroupType.EPOS_AUTH_CONFIRM, "快捷通-预授权完成");
        nameMap.put(GroupType.EPOS_AUTH_FREEZE, "快捷通-预授权申请");
        nameMap.put(GroupType.EPOS_PAY_SMS, "快捷通-新消费");
        nameMap.put(GroupType.EPOS_AUTH_SMS, "快捷通-新预授权");

        nameMap.put(GroupType.WEB_BANK, "网银-支付");
        nameMap.put(GroupType.WECHAT_IMG, "微信-扫码支付");
        nameMap.put(GroupType.WECHAT_MOBILE, "微信-APP支付");
        nameMap.put(GroupType.WECHAT_UNIFY, "微信-统一支付");
        nameMap.put(GroupType.ALI_DIRECT, "支付宝-面对面支付");
        nameMap.put(GroupType.ALI_SDK, "支付宝-钱包支付");

        nameMap.put(GroupType.QUERY_EPOS_BANK, "查询-快捷通银行");
        nameMap.put(GroupType.QUERY_OPER, "查询-流水详情");
        nameMap.put(GroupType.QUERY_ORDER, "查询-订单详情");
        nameMap.put(GroupType.QUERY_WEB_BANK, "查询-网银银行");
        nameMap.put(GroupType.QUERY_CARD_INFO, "查询-卡信息");
        nameMap.put(GroupType.QUERY_CREDITCARD_BIND, "查询-绑卡信息");
        nameMap.put(GroupType.QUERY_SUPPORT, "查询-银行列表（新）");

        nameMap.put(GroupType.CREATE_NO, "其他-创建交易流水");
        nameMap.put(GroupType.COMPLETE_INFO, "其他-完善交易流水");
        nameMap.put(GroupType.CREATE_NO_SMS, "其他-交易鉴权验证码");
        nameMap.put(GroupType.UNBIND_CREDIT_CARD, "其他-解绑信用卡");
        nameMap.put(GroupType.BILL_DOWNLOAD, "其他-电子小票下载");

        nameMap.put(GroupType.POS_PAY, "线下POS-消费");
        nameMap.put(GroupType.POS_PAY_CANCEL, "线下POS-消费撤销");
        nameMap.put(GroupType.POS_PAY_REFUND, "线下POS-消费退款");
        nameMap.put(GroupType.POS_AUTH_CANCEL, "线下POS-预授权撤销");
        nameMap.put(GroupType.POS_AUTH_CONF_CANCEL, "线下POS-预授权完成撤销");
        nameMap.put(GroupType.POS_AUTH_CONFIRM, "线下POS-预授权完成");
        nameMap.put(GroupType.POS_AUTH_FREEZE, "线下POS-预授权申请");

        nameMap.put(GroupType.PAYPAL_BIND, "PAYPAL-绑定账户");
        nameMap.put(GroupType.PAYPAL_PAY, "PAYPAL-快捷支付");
        nameMap.put(GroupType.PAYPAL_UNBIND, "PAYPAL-解绑账户");

        nameMap.put(GroupType.DRAWING, "提现转账");
        nameMap.put(GroupType.QUERY_DRAWING, "查询-提现结果");

        nameMap.put(GroupType.APPLE_PAY, "APPLEPAY-银联支付");
        nameMap.put(GroupType.PCI_QUERY, "查询-用户PCI绑卡信息");
        nameMap.put(GroupType.EPOS_QUICK_PAY_SMS, "快捷通-二次发短信");
        nameMap.put(GroupType.EPOS_REQUICK_PAY, "快捷通-二次消费");

        nameMap.put(GroupType.EASY_LINK_WEBPAY, "易联H5支付");
        nameMap.put(GroupType.EASY_LINK_SMS_H5, "易联短信H5支付");
        nameMap.put(GroupType.EASY_LINK_SDK_PASS, "易联SDK密码键盘");

        nameMap.put(GroupType.OPEN_API, "开放平台第三方支付调用");

        nameMap.put(GroupType.UNION_AUTH, "银联-预授权申请");
        nameMap.put(GroupType.UNION_AUTH_CONFIRM, "银联-预授权完成");
        nameMap.put(GroupType.UNION_AUTH_CANCEL, "银联-预授权申请撤销");
        nameMap.put(GroupType.UNION_AUTH_CONFIRM_CANCEL, "银联-预授权完成撤销");
        nameMap.put(GroupType.UNION_SEND_SMS, "银联-发送短信");
        nameMap.put(GroupType.UNION_SMS_PAY, "银联-消费");
        nameMap.put(GroupType.UNION_QUICK_PAY, "银联-直接消费");
        nameMap.put(GroupType.UNION_APP_PAY, "银联-云闪付APP消费");
        nameMap.put(GroupType.UNION_WEB_PAY, "银联-网银消费");
        nameMap.put(GroupType.UNION_REFUND, "银联-消费退款");
        nameMap.put(GroupType.UNION_CANCEL, "银联-消费撤销");

    }

    private GroupType() {
    }

    /**
     *
     * <br/> Created on 2014-1-9 下午2:10:42
     * @author  李青原(liqingyuan1986@aliyun.com)
     * @since 2.1
     * @param groupType
     * @return
     */
    public static String getTypeName(String groupType){
        return nameMap.get(groupType);
    }


    /**
     * 获得交易类型对应交易操作类型
     * @param groupType
     * @return
     */
    public static String getOperType(String groupType){
        String[] payArray = {EPOS_PAY,WEB_BANK,WECHAT_IMG,WECHAT_MOBILE,ALI_DIRECT,EPOS_PAY_SMS,WECHAT_UNIFY, ALI_SDK, POS_PAY, PAYPAL_PAY,EPOS_REQUICK_PAY,APPLE_PAY,
                EASY_LINK_WEBPAY,EASY_LINK_SMS_H5,EASY_LINK_SDK_PASS,
                UNION_SMS_PAY,UNION_QUICK_PAY,UNION_APP_PAY,UNION_WEB_PAY
        };
        String[] refundArray = {EPOS_PAY_REFUND,POS_PAY_REFUND,UNION_REFUND};
        String[] cancelArray = {EPOS_PAY_CANCEL,POS_PAY_CANCEL,UNION_CANCEL};
        String[] authArray = {EPOS_AUTH_FREEZE,EPOS_AUTH_SMS,POS_AUTH_FREEZE,UNION_AUTH};
        String[] authCancelArray = {EPOS_AUTH_CANCEL,POS_AUTH_CANCEL,UNION_AUTH_CANCEL};
        String[] authConfirmArray = {EPOS_AUTH_CONFIRM,POS_AUTH_CONFIRM,UNION_AUTH_CONFIRM};
        String[] authConfCancelArray = {EPOS_AUTH_CONF_CANCEL,POS_AUTH_CONF_CANCEL,UNION_AUTH_CONFIRM_CANCEL};
        String[] queryArray = {QUERY_EPOS_BANK,QUERY_OPER,QUERY_ORDER,QUERY_WEB_BANK,QUERY_CARD_INFO,QUERY_CREDITCARD_BIND,QUERY_SUPPORT,QUERY_DRAWING};
        String[] otherArray = {CREATE_NO,COMPLETE_INFO,CREATE_NO_SMS,UNBIND_CREDIT_CARD,BILL_DOWNLOAD, PAYPAL_BIND, PAYPAL_UNBIND,EPOS_QUICK_PAY_SMS,PCI_QUERY,
                UNION_SEND_SMS
        };
        String[] drawArray = {DRAWING};
        if(ArrayUtils.indexOf(payArray, groupType) != -1){
            return OperType.PAY;
        }
        if(ArrayUtils.indexOf(refundArray, groupType) != -1){
            return OperType.REFUND;
        }
        if(ArrayUtils.indexOf(cancelArray, groupType) != -1){
            return OperType.CANCEL;
        }
        if(ArrayUtils.indexOf(authArray, groupType) != -1){
            return OperType.AUTH_FREEZE;
        }
        if(ArrayUtils.indexOf(authCancelArray, groupType) != -1){
            return OperType.AUTH_CANCEL;
        }
        if(ArrayUtils.indexOf(authConfirmArray, groupType) != -1){
            return OperType.AUTH_CONFIRM;
        }
        if(ArrayUtils.indexOf(authConfCancelArray, groupType) != -1){
            return OperType.AUTH_CONF_CANCEL;
        }
        if(ArrayUtils.indexOf(queryArray, groupType) != -1){
            return OperType.QUERY;
        }
        if(ArrayUtils.indexOf(otherArray, groupType) != -1){
            return OperType.OTHER;
        }
        if(ArrayUtils.indexOf(drawArray, groupType) != -1){
            return OperType.DRAWING;
        }
        return OperType.OTHER;
    }
}
